package com.jilian.mydemo.modul.order.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jilian.mydemo.R;
import com.jilian.mydemo.common.dto.MemberDto;
import com.jilian.mydemo.common.dto.PathDto;
import com.jilian.mydemo.listener.CustomItemClickListener;
import com.jilian.mydemo.utils.EmptyUtils;

import java.util.List;

/**
 * 水工列表
 */
public class HydraulicListAdapter extends RecyclerView.Adapter<HydraulicListAdapter.ViewHolder> {
    private Activity mContext;
    private List<MemberDto> datas;
    private CustomItemClickListener listener;

    public HydraulicListAdapter(Activity context, List<MemberDto> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;


    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_hydrauliclist, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, listener);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if (position == datas.size() - 1) {
            holder.vLine.setVisibility(View.GONE);

        } else {
            holder.vLine.setVisibility(View.VISIBLE);
        }

        holder.tvName.setText(datas.get(position).getUserName());
        //计时
        if ("1".equals(datas.get(position).getBillingType()))
        {
            if (EmptyUtils.isNotEmpty(datas.get(position).getWorkload())) {
                if (datas.get(position).getWorkload().contains("小时")) {
                    holder.tvStopTime.setText(datas.get(position).getWorkload());
                } else {
                    holder.tvStopTime.setText(datas.get(position).getWorkload() + "小时");
                }

            } else {
                holder.tvStopTime.setHint("请选择工时");
            }
        }
        //计件
        if ("2".equals(datas.get(position).getBillingType()))
        {
            if (EmptyUtils.isNotEmpty(datas.get(position).getWorkload())) {
                if (datas.get(position).getWorkload().contains("件")) {
                    holder.tvStopTime.setText(datas.get(position).getWorkload());
                } else {
                    holder.tvStopTime.setText(datas.get(position).getWorkload() + "件");
                }

            } else {
                holder.tvStopTime.setHint("请选择完成件数");
            }
        }

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private View vLine;
        private TextView tvName;
        private TextView tvStopTime;


        public ViewHolder(final View itemView, final CustomItemClickListener listener) {
            super(itemView);
            vLine = (View) itemView.findViewById(R.id.v_line);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvStopTime = (TextView) itemView.findViewById(R.id.tv_stop_time);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    listener.onItemClick(itemView, getAdapterPosition());
                }
            });


        }

    }
}
